import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home.vue'
import store from '@/store/index.js'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/playlist',
    name: 'PlayList',
    component: () => import('@/components/childCom/PlayList.vue')
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('@/components/Search.vue')
  },
  {
    path: '/songrcmd',
    name: 'Songrcmd',
    component: () => import('@/components/childCom/Songrcmd.vue')
  },
  {
    path: '/rnpage',
    name: 'RnPage',
    component: () => import('@/components/childCom/RnPage.vue')
  },
  {
    path: '/detail',
    name: 'Detail',
    component: () => import('@/components/childCom/AlbumList.vue')
  },
  {
    path: '/albumdetail',
    name: 'AlbumDetail',
    component: () => import('@/components/AlbumDetail.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login.vue')
  },
  {
    path: '/me',
    name: 'Me',
    beforeEnter: (to, from, next) => {
      console.log(store.state.user);
      if (store.state.user.isLogin) {
        next()
      } else {
        next('/login')
      }
    },
    component: () => import('@/views/Me.vue')

  },

]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
